package com.team.employment.web.admin.controller.user;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.team.employment.common.result.Result;
import com.team.employment.common.result.ResultCodeEnum;
import com.team.employment.model.entity.UserInfo;
import com.team.employment.model.enums.VerifyStatus;
import com.team.employment.web.admin.custom.check.IdIsEmptyCheck;
import com.team.employment.web.admin.dto.UserQueryDto;
import com.team.employment.web.admin.service.UserInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "用户信息管理")
@RestController
@RequestMapping("/admin/userInfo")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    private IdIsEmptyCheck idIsEmptyCheck;

    @Operation(summary = "分页查询所有用户账号信息")
    @GetMapping("pageInfo")
    public Result<IPage<UserInfo>> pageInfo(@RequestParam long current, @RequestParam long size){
        IPage<UserInfo> page = new Page<>(current,size);
        IPage<UserInfo> resultPage = userInfoService.page(page);
        return Result.ok(resultPage);
    }

    @Operation(summary = "根据条件模糊分页查询用户列表")
    @PostMapping("pageQueryInfo")
    public Result<IPage<UserInfo>> pageQueryInfo(@RequestParam long current, @RequestParam long size, @RequestBody UserQueryDto userQueryDto){
        IPage<UserInfo> page = new Page<>(current,size);
        IPage<UserInfo> list =userInfoService.pageQueryInfo(page,userQueryDto);
        return Result.ok(list);
    }

    @Operation(summary = "根据user_id删除用户")
    @DeleteMapping("removeById/{id}")
    public Result removeById(@PathVariable Long id){
        idIsEmptyCheck.idIsEmpty(userInfoService,id);
        userInfoService.removeUserAndRelatedResume(id);
        return Result.ok();
    }

    @Operation(summary = "根据user_id和status更新账号状态")
    @PutMapping("updateById")
    public Result updateById(@RequestParam Long id,@RequestParam VerifyStatus verifyStatus){

        LambdaUpdateWrapper<UserInfo> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(UserInfo::getId,id).set(UserInfo::getStatus,verifyStatus);
        userInfoService.update(lambdaUpdateWrapper);
        return Result.ok();
    }

}
